package com.myfoon.model.cacheable;

import com.myfoon.model.entity.Photo;

import com.tangosol.io.ExternalizableLite;

import com.tangosol.util.ExternalizableHelper;

import java.io.DataInput;
import java.io.DataOutput;

import java.io.IOException;

import java.sql.Timestamp;

public class PhotoCache implements ExternalizableLite {
    private Long id;
    private Long ownerId;
    private String src;
    private String srcsmall;
    private Timestamp created;
    
    public PhotoCache() {
    }
    
    public PhotoCache(Photo p) {
        this.id = p.getId();
        this.ownerId = p.getOwner().getId();
        this.src = p.getSrc();
        this.srcsmall = p.getSrcsmall();
        this.created = p.getCreated();
    }

    public void readExternal(DataInput dataInput) throws IOException {
        id = dataInput.readLong();
        ownerId = dataInput.readLong();
        src = dataInput.readUTF();
        srcsmall = dataInput.readUTF();
        created = ExternalizableHelper.readTimestamp(dataInput);
    }

    public void writeExternal(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(id);
        dataOutput.writeLong(ownerId);
        dataOutput.writeUTF(src);
        dataOutput.writeUTF(srcsmall);
        ExternalizableHelper.writeTimestamp(dataOutput, created);
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    public Long getOwnerId() {
        return ownerId;
    }

    public void setSrc(String src) {
        this.src = src;
    }

    public String getSrc() {
        return src;
    }

    public void setSrcsmall(String srcsmall) {
        this.srcsmall = srcsmall;
    }

    public String getSrcsmall() {
        return srcsmall;
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }

    public Timestamp getCreated() {
        return created;
    }
}
